/*
 * @Author: your name
 * @Date: 2022-03-01 20:13:10
 * @LastEditTime: 2022-03-01 21:06:41
 * @LastEditors: Please set LastEditors
 * @Description: 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 * @FilePath: \the-way-of-interview\convertNumber.js
 */
/**
 * 把数字转为汉字数字
 * @param {*} value 
 * @returns 
 */
function convertNumber(value) {
    if(! value || ! isNaN(value)) {
        let chinese = ['零','一','二','三','四','五','六','七','八','九']
        let unit = ['','十','百','千','万','十','百','千','亿','十','百','千','万','十','百','千','亿']
        let str = value.toString().split('');
        let res = ''
        for (let i=0;i<str.length;i++) {
            let d = str.length -1 -i;
            res =unit[i] + res ;
            let unit_i = str[d];
            res = chinese[unit_i] + res;
        }
        return res;
    }
}

console.log(convertNumber(123456))
